package com.lianyu507;

import com.lianyu507.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
@ComponentScan
public class WebConfig extends WebMvcConfigurerAdapter {

	    @Override
	    public void addResourceHandlers(ResourceHandlerRegistry registry) {
	        registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/static/");
	        super.addResourceHandlers(registry);  
	        }

	    
	    @Override
	    public void addInterceptors(InterceptorRegistry registry) {
	        //拦截规则：除了index,login,邮箱，其他都拦截判断
	        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**").excludePathPatterns("/portal/login").excludePathPatterns("/portal/login/needLogin").excludePathPatterns("/portal/index").excludePathPatterns("/error/index").excludePathPatterns("/bindEmail").excludePathPatterns("/sendEmail");
	          super.addInterceptors(registry);
	    }
}
